package com.vibration.web.controller.baseinfo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vibration.common.annotation.Log;
import com.vibration.common.core.controller.BaseController;
import com.vibration.common.core.domain.AjaxResult;
import com.vibration.common.enums.BusinessType;
import com.vibration.baseinfo.domain.CzCard;
import com.vibration.baseinfo.service.ICzCardService;
import com.vibration.common.utils.poi.ExcelUtil;
import com.vibration.common.core.page.TableDataInfo;

/**
 * 物联网卡Controller
 * 
 * @author Mr_Wu
 * @date 2023-01-31
 */
@RestController
@RequestMapping("/baseinfo/card")
public class CzCardController extends BaseController
{
    @Autowired
    private ICzCardService czCardService;

    /**
     * 查询物联网卡列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzCard czCard)
    {
        startPage();
        List<CzCard> list = czCardService.selectCzCardList(czCard);
        return getDataTable(list);
    }

    @GetMapping("/warnCount")
    public AjaxResult warnCount()
    {
        AjaxResult result = AjaxResult.success();
        Integer count = czCardService.selectCzCardWarnCount();
        result.put(AjaxResult.DATA_TAG,count);
        return result;
    }

    /**
     * 导出物联网卡列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:export')")
    @Log(title = "物联网卡", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzCard czCard)
    {
        List<CzCard> list = czCardService.selectCzCardList(czCard);
        ExcelUtil<CzCard> util = new ExcelUtil<CzCard>(CzCard.class);
        util.exportExcel(response, list, "物联网卡数据");
    }

    /**
     * 获取物联网卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(czCardService.selectCzCardById(id));
    }

    /**
     * 新增物联网卡
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:add')")
    @Log(title = "物联网卡", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzCard czCard)
    {
        return toAjax(czCardService.insertCzCard(czCard));
    }

    /**
     * 修改物联网卡
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:edit')")
    @Log(title = "物联网卡", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzCard czCard)
    {
        return toAjax(czCardService.updateCzCard(czCard));
    }

    /**
     * 删除物联网卡
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:remove')")
    @Log(title = "物联网卡", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(czCardService.deleteCzCardByIds(ids));
    }

    /**
     * 更新物联网卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:card:query')")
    @GetMapping(value = "/updateCardFlow")
    public AjaxResult updateCardFlow(){
        czCardService.updateCardFlow();
        return AjaxResult.success();
    }
}
